package llm

import (
	"context"

	mark3labs "github.com/mark3labs/mcp-go/mcp"
)

const (
	RoleUser      = "user"
	RoleSys       = "system"
	RoleAssistant = "assistant"
	RoleTool      = "tool"
)

type RoleContent struct {
	Role    string
	Content string
}

type Message interface {
	// GetRole returns the role of the message sender (e.g., "user", "assistant", "system")
	GetRole() string

	// GetContent returns the text content of the message
	GetContent() string

	// GetToolCalls returns any tool calls made in this message
	GetToolCalls() []ToolCall

	// IsToolResponse returns true if this message is a response from a tool
	IsToolResponse() bool

	// GetToolResponseID returns the ID of the tool call this message is responding to
	GetToolResponseID() string

	// GetUsage returns token usage statistics if available
	GetUsage() (input int, output int)
}

type ChatReq struct {
	Model               string
	Msgs                []RoleContent
	RspChan             chan string
	CompleteChan        chan bool
	Tools               []mark3labs.Tool
	CompleteMessageChan chan Message
}

type CompleteReq struct {
	Model   string
	Msgs    []RoleContent
	Options map[string]interface{}
	Tools   []mark3labs.Tool
}

type EmbeddingReq struct {
	Model  string
	Prompt string
}

type Progress struct {
	Current int32
	Max     int32
}

type ImageReq struct {
	Prompt     string
	Extra      string
	Preview    bool
	PreviewCh  chan string
	ProgressCh chan Progress
	QueueCh    chan int32
	CmdTypeCh  chan string
	ID         chan string
}

type ImageInfo struct {
	FileName string
	Img      []byte
}

type LLMClientConfig struct {
	BaseUrl  string
	AuthInfo string
	// SecretKey string
	// AccessKey string
	Model string
}

type LLM_Embedding interface {
	Embedding(ctx context.Context, req *EmbeddingReq) ([]float64, error)
}

type LLM_Chat interface {
	Complete(ctx context.Context, req *CompleteReq) (Message, error)
	Chat(ctx context.Context, req *ChatReq) error
	GetProviderName() string
}

type LLM_Image interface {
	// User model related methods.
	Image(ctx context.Context, messages *ImageReq) (string, error)
}

type ToolCall interface {
	// GetName returns the tool's name
	GetName() string

	// GetArguments returns the arguments passed to the tool
	GetArguments() map[string]interface{}

	// GetID returns the unique identifier for this tool call
	GetID() string
}
